# $Id: PKGBUILD 88646 2013-04-21 04:42:42Z fyan $
# Maintainer: Felix Yan <felixonmars@gmail.com>
# Contributor: cuihao <cuihao dot leo at gmail dot com>
# Contributor: Guten <ywzhaifei@gmail.com> 

pkgname=goagent
pkgver=2.1.17
pkgrel=1
pkgdesc="A gae proxy forked from gappproxy/wallproxy"
arch=("any")
url="http://goagent.googlecode.com"
license=("GPL2")
depends=('python2' 'python2-pyopenssl' 'python2-gevent-beta')
source=(https://github.com/goagent/goagent/archive/v$pkgver.tar.gz
        $pkgname.service)
backup=('etc/goagent')
install=goagent.install

package() {
  cd "$srcdir/$pkgname-$pkgver"

  # python2 fix
  sed -i -re "1s/python2?/python2/" local/*.py
  chmod +x local/proxy.py

  mkdir -p "$pkgdir/opt/goagent"
  cp -r local server "$pkgdir/opt/goagent"
  
  # remove Windows-only files
  rm -f "$pkgdir/opt/goagent/"*/*.{vbs,dll,exe,manifest,bat}
  rm -f "$pkgdir/opt/goagent/local/python27.zip"

  # remove Mac-only files
  rm -f "$pkgdir/opt/goagent/local/goagent-osx.py"

  # remove goagent-gtk
  rm -f "$pkgdir/opt/goagent/local/goagent-gtk.py"
  rm -f "$pkgdir/opt/goagent/local/logo.png"
  rm -f "$pkgdir/opt/goagent/local/addto-startup.py"

  # remove CA.crt CA.key for security issues
  rm -f "$pkgdir/opt/goagent/local/CA.crt" "$pkgdir/opt/goagent/local/CA.key"
  rm -rf "$pkgdir/opt/goagent/local/certs"

  # config file
  install -Dm644 "${pkgdir}/opt/goagent/local/proxy.ini" "${pkgdir}/etc/goagent"
  ln -sf "/etc/goagent" "${pkgdir}/opt/goagent/local/proxy.ini"

  # systemd service
  install -Dm644 "${srcdir}/goagent.service" "${pkgdir}/usr/lib/systemd/system/goagent.service"
}

# vim:set ts=2 sw=2 et:
md5sums=('5ee022e802b927531e302f8c9aa83711'
         'e49aca604fcbf7b64d07460d33669640')
